//
//  PPOtherInfoTableViewController.m
//  pet
//
//  Created by 陈无忌 on 10/9/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPOtherInfoTableViewController.h"
#import "PPUserQRCodeViewController.h"
#import "supportingHeadFiles.h"

@interface PPOtherInfoTableViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *userAvatar;
@property (weak, nonatomic) IBOutlet UILabel *QRCodeTitle;

@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *userAgeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *userGenderLabel;
@property (weak, nonatomic) IBOutlet UILabel *signatureLabel;


@end

@implementation PPOtherInfoTableViewController

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setTitle:[NSString stringWithFormat:@"%@的资料",self.user.userName]];
    [self userInfoLoad];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(void)userInfoLoad
{
    [self.userAvatar setImageWithURL:[PPImageUrl getImageUrl:self.user.userAvatar] placeholderImage:[UIImage imageNamed:@"defaultAvatar"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.userNameLabel.text = self.user.userName;
    if (self.user.birth) {
        self.userAgeLabel.text = self.user.birth;
    }else{
        self.userAgeLabel.text = @"未设置";
    }
    
    self.addressLabel.text = self.user.address;
    if (self.user.signature.length > 0) {
        self.signatureLabel.text = self.user.signature;
    }else{
        self.signatureLabel.text = @"主人比较懒，什么都没写";
    }
    switch (self.user.gender) {
        case 0:
            self.userGenderLabel.text = @"先生";
            self.QRCodeTitle.text = @"他的二维码";
            break;
        case 1:
            self.userGenderLabel.text = @"女士";
            self.QRCodeTitle.text = @"她的二维码";
            break;
        default:
            break;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table View delegate

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 14;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 14)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1 && indexPath.row == 5) {
        PPUserQRCodeViewController *targetVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PPUserQRCodeViewController"];
        targetVC.user = self.user;
        [self.navigationController pushViewController:targetVC animated:YES];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
